/**
 * 系统角色添加js
 */
var comValidform=null;
var returnStatus=false;
var sysRoleAdd={
	dataCache:null,
		
	startEvent:function(){
		comValidform=$(".com-addForm").Validform({
			tiptype:2,
			tipSweep:true,
			beforeSubmit:function(curform){
				var checkedId='';
				$('.com-addForm').find('input:checkbox[name="moduleList"]:checked').each(function(){
					var checkedVal=$(this).val();
					checkedId+=checkedVal.split(':')[0]+',';
				});
				if(checkedId!='')
					checkedId=checkedId.substring(0,checkedId.length-1);
				$('.com-addForm input[name="sysModuleIds"]').val(checkedId);
				
				var url = 'mgr/SysRoleCtrl/saveSysRole';
				var params = jsUtils.serializeJson($('.com-addForm'));
				delete params.moduleList;
				params.orgType = $('.com-addForm input[name="orgType"]:checked').val();

				var cb = function(data){
					alert(data.msg);
					//成功返回
					if(data.resultCode==200){
						//关闭窗口并刷新数据
						art.dialog.close();
						returnStatus=true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return false;
			}
		});
		
		//获取所有模块
		var url ='mgr/SysModuleCtrl/getSysModuleList';
		var params={
			'curPage':0,
			'pageSize':9999
		};
		var cb = function(data){
			sysRoleAdd.dataCache=data.result;
			var modulesCache=sysRoleAdd.dataCache;
			var tr='';
			for(var i=0;i<modulesCache.length;i++){
				if(i%3==0){
					tr+='<tr style="height: 25px;">';
				}
				var id=modulesCache[i].sysModule.id;
				var name=modulesCache[i].sysModule.name;
				tr+='<td><input type="checkbox" name="moduleList" value="'+id+':'+name+'" />'+name+'</td>';
				if(i%3==2){
					tr+='</tr>';
				}
			}
			$('#moduleTable').append(tr);
		};
		sendApiNoLoad(url, params, cb, 'POST');
	},
	
	init:function(){
		sysRoleAdd.startEvent();
	}
}
$(document).ready(function() {
	sysRoleAdd.init();
});
function submitForm(){
	comValidform.submitForm();
	return returnStatus;
}